from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=op)

driver.get(r"http://news.baidu.com/")
content = driver.find_element(By.CSS_SELECTOR,".hdline1>strong>a")
content.click()
url = content.get_attribute("href")
sleep(2)
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
title_url = driver.current_url
assert url in title_url
sleep(2)
driver.close()
driver.switch_to.window(all_handles[0])
driver.find_element(By.CSS_SELECTOR,"#ww").send_keys("谁是帅哥")
sousuo = driver.find_element(By.CSS_SELECTOR,"#s_btn_wr")
sousuo.click()
sleep(2)
assert "谁是帅哥" in driver.page_source
driver.quit()